<!--
 * @FilePath     : /study_code/jquery/plugin-jquery-tmpl-option.html
 * @Description  : 使用配置项 和 $item, $data 属性
 * @Date         : 2025-04-21 13:59:06
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-21 14:29:48
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
  </head>
  <body>
    <div id="div_item_data"></div>

    <script id="item_data" type="text/x-jquery-tmpl">
      <div style="margin-bottom:10px;">
        <span>${id}</span>
        <span>${$data.name}</span>
        <span style="margin-left:10px;">${$item.getLangs(";")}</span>
      </div>
    </script>

    <script src="/jquery/dist/jquery.min.js"></script>
    <script src="/jquery/plugins/jquery.tmpl/lib/jquery.tmpl.min.js"></script>

    <script>
      $(function () {
        var users = [
          {
            id: 'think8848',
            name: ['Joseph', 'Chan'],
            Langs: ['Chinese', 'English'],
          },
          {
            id: 'aCloud',
            name: ['Mary', 'Cheung'],
            Langs: ['Chinese', 'French'],
          },
        ]

        // .tmpl() 第2参数，传入一个参数对象（值为函数）
        $('#item_data')
          .tmpl(users, {
            getLangs: function (separator) {
              // this.data 指向当前渲染的数据 users
              return this.data.Langs.join(separator)
            },
          })
          .appendTo('#div_item_data')
      })
    </script>
  </body>
</html>
